﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layuimini/css/public.css" rel="stylesheet" />
    <style>
        td .layui-table-cell {
            height: 100px;
            line-height: 100px;
        }
    </style>
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <script type="text/html" id="TableToolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                    <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
                </div>
            </script>
            <table class="layui-hide" id="table" lay-filter="TableFilter"></table>
            <script type="text/html" id="TableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">修改备注</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            </script>
        </div>
    </div>
    <script src="~/layui/layui.js"></script>
    <script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#table',
            method: 'post',
            url: '@Url.Action("ImagesListAsync", "Default")',
            request: {
                pageName: 'PageIndex' //页码的参数名称，默认：page
               , limitName: 'PageSize' //每页数据量的参数名，默认：limit
            },
            where: {
                GroupID: 1,
                ItemID: 1,
                FileType: 'img',
            },
            toolbar: '#TableToolbar',
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [[
                { type: "checkbox", width: 50 },
                { field: 'ID', title: 'ID' },
                { field: 'Remark', title: '备注'},
                { field: 'FileSize', title: '大小' },
                {
                    field: 'url', title: '预览',
                    templet: function (d) {
                        return '<div><img  src= "' + d.url + '" alt="" height="90px"></a></div>';
                    }, event: 'preview'
                },
                {
                    field: 'url', title: '操作',
                    templet: '#TableBar'
                }
            ]],
            limits: [10, 20, 30, 50, 100],
            limit: 20,
            page: true,
            //skin: 'line',
            height: 'full-70',
            //size:'sm',
        });


        /**
         * toolbar监听事件
         */
        table.on('toolbar(TableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('table')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(TableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(TableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/edit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'preview') {
                layer.photos({
                    photos: {
                        "title": "", //相册标题
                        "id": 123, //相册id
                        "start": 0, //初始显示的图片序号，默认0
                        "data": [   //相册包含的图片，数组格式
                          {
                              "alt": "",
                              "pid": 1, //图片id
                              "src": obj.data.url, //原图地址
                              "thumb": obj.data.url //缩略图地址
                          }
                        ]
                    } //格式见API文档手册页
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
                });
            }
        });
        function RefreshTable() {
            table.reload('table', {
                where: {
                    Search: $('#name').val()
                }
            }, 'data');
        }
    });
    </script>
</body>
</html>